﻿using MediatR;
using NLog.Web.LayoutRenderers;
using S.Organization.Domian.dto;
using S.Organization.Domian.Model;
using S.Organization.Infrastructure;
using S.Organization.Read.API.Application.Command.SupplierCommand;

namespace S.Organization.Read.API.Application.CommandHandler.SupplierCommandHandler
{
    public class SelectSupplierCommandHandler:IRequestHandler<SelectSupplierCommand,List<DTO>>
    {
        private readonly IBaseRepository<Supplier> _repository;


        public SelectSupplierCommandHandler(IBaseRepository<Supplier> repository)
        {
            _repository = repository;
        }

        public async Task<List<DTO>> Handle(SelectSupplierCommand request, CancellationToken cancellationToken)
        {
            var query = await   _repository.AllAsync();
            List<DTO> result = new List<DTO>();
            foreach (var item in query)
            {
                var a = new DTO();
                a.Id=item.SupplierId;
                a.Name=item.SupplierName;
                result.Add(a);
            }
            return result;
        }
    }
}
